package com.zyfdroid.ambernicstartmenu.ui;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
import android.view.Display;
import android.view.WindowManager;
import android.widget.EditText;
import com.zyfdroid.ambernicstartmenu.R;

public class EditWalkthroughActivity extends Activity {
    EditText editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_edit_walkthrough);
        editText = findViewById(R.id.txtWalkthoughEdit);
        editText.setText(getWalkthrough());
        WindowManager m = getWindowManager();
        Display d = getDisplay(); // 为获取屏幕宽、高
        android.view.WindowManager.LayoutParams p = getWindow().getAttributes();
        p.height = (int) (d.getHeight() * 0.95); // 高度设置为屏幕的0.3
        p.width = (int) (d.getWidth() * 0.7); // 宽度设置为屏幕的0.7
        getWindow().setAttributes(p);
    }

    private String getWalkthrough(){
        return getDefault().getString("walkthough","尚未记载攻略。或许可以点击右上角的记载按钮记一些什么。");
    }
    private void setWalkthrough(){
        getDefault().edit().putString("walkthough",editText.getText().toString()).apply();
    }
    private SharedPreferences getDefault(){
        return getSharedPreferences("default",MODE_PRIVATE);
    }

    @Override
    protected void onPause() {
        super.onPause();
        setWalkthrough();
    }

}
